# 下载csv中的所有图片
import pandas as pd
import os
import requests

# 读取csv文件
df = pd.read_csv('t_visual_card.csv')
base_url = 'https://fanxiao.oss-cn-guangzhou.aliyuncs.com/'

# 下载图片
for index, row in df.iterrows():
    # 目录分开
    base_folder = 'download/'
    folder_name = row['file_name'].split('/')[0]
    last_file_name = row['file_name'].split('/')[1]
    if not os.path.exists(base_folder + folder_name):
        os.makedirs(base_folder + folder_name)
    if last_file_name == 'w':
        if not os.path.exists(base_folder + folder_name + '/w'):
            os.makedirs(base_folder + folder_name + '/w')
        last_file_name = row['file_name'].split('/')[2]
        image_url = base_url + row['file_name']
        response = requests.get(image_url)
        with open(base_folder + folder_name + '/w/' + last_file_name, 'wb') as f:
            f.write(response.content)
            print(base_folder + folder_name + '/w/' + last_file_name)
    else:
        image_url = base_url + row['file_name']
        response = requests.get(image_url)
        with open(base_folder + folder_name + '/' + last_file_name, 'wb') as f:
            f.write(response.content)
            print(base_folder + folder_name + '/' + last_file_name)
print("下载完成")